package com.dems.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dems.dao.MpDao;
import com.dems.dao.RepairDao;
import com.dems.domain.Mp;

/**
 * Servlet implementation class OkRepairResultServlet
 */
@WebServlet("/MpRepairResultServlet")
public class MpRepairResultServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private RepairDao repairDao = new RepairDao();
    private MpDao mpDao = new MpDao();
    public MpRepairResultServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Mp mp = (Mp)request.getSession().getAttribute("mp");
		String mpNum = mp.getMpNum();
		Mp m = mpDao.selectOne(mpNum);
		String mpName = m.getMpName();
		String mpPhone = m.getMpPhone();
		int repairId = Integer.parseInt(request.getParameter("repairId"));
		String repairState = request.getParameter("button");
		if (repairState.equals("toRepair")) {
			repairState = "正在维修";
			repairDao.toRepair(repairId,mpName,mpPhone,repairState);
		}
		if (repairState.equals("complete")) {
			repairState = "维修完成";
			repairDao.repairResult(repairId,repairState);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
